//
//  MenuScene.swift
//  mng
//
//  Created by WTFKL on 2018/4/12.
//  Copyright © 2018年 WTF. All rights reserved.
//

import GameplayKit
import SpriteKit

class MenuScene: SKScene {
    private var startButton : MeCustomButton?;
    private var instructions : MeCustomButton?;

    
    override func didMove(to view: SKView) {
        initView();
        
    }
    
    func initView(){
        startButton = MeCustomButton(btnName: "start", btnSize:CGSize(width: 100, height: 50) , btnCornerRadius: 5);
        startButton?.position = CGPoint(x: 0, y: 5);
        startButton?.m_fontColor = .white;
        startButton?.m_BackgroundColor = .clear;
        startButton?.m_FontName = "GB18030Bitmap";
        startButton?.m_LabelText = "开始";
        startButton?.m_FontSize = 35;
        startButton?.borderColor = .white;
        startButton?.m_borderLineWidth = 1;
        startButton?.clickEvent = {
            let firstScene = SKScene(fileNamed: "Third")!
//            firstScene.size = CGSize(width: UIScreen.main.bounds.size.width * 2, height: UIScreen.main.bounds.size.height * 2);
//            firstScene.scaleMode = .aspectFill;
            self.view?.presentScene(firstScene,transition: SKTransition.crossFade(withDuration: 0.5));
        };
        self.addChild(startButton!);
        
        instructions = MeCustomButton(btnName: "instructions", btnSize:CGSize(width: 100, height: 50) , btnCornerRadius: 5);
        instructions?.position = CGPoint(x: 0, y: -70);
        instructions?.m_fontColor = .white;
        instructions?.m_BackgroundColor = .clear;
        instructions?.m_FontName = "GB18030Bitmap";
        instructions?.m_LabelText = "说明";
        instructions?.m_FontSize = 35;
        instructions?.borderColor = .white;
        instructions?.m_borderLineWidth = 1;
        instructions?.clickEvent = {
            let instructScene = SKScene(fileNamed: "InstructionScene")!
//            instructScene.size = UIScreen.main.bounds.size;
//            instructScene.scaleMode = .aspectFill;
             self.view?.presentScene(instructScene,transition: SKTransition.crossFade(withDuration: 0.5));
        };
        self.addChild(instructions!);
        
    
    }
   
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        for t in touches {
            let location = t.location(in: self);
            
            let mnode = nodes(at: location);
            
            for nnode in mnode{
                let na = nnode as? MeCustomButton;
                if(na?.name == "instructions"){
                    instructions?.touchUpInside(highLightBGColor: .white, highLightFontColor: .black);
                }else if(na?.name == "start"){
                    startButton?.touchUpInside(highLightBGColor: .white, highLightFontColor: .black);
                }
            }
        }
    }
}
